<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
		<title>应诊</title>
		<link rel="stylesheet" type="text/css" href="../css/hui.css" />
		<link rel="stylesheet" type="text/css" href="../css/common.css" />
		<link rel="stylesheet" type="text/css" href="../css/homepage.css" />
		<script src="../js/common/flexible_css.debug.js" type="text/javascript" charset="utf-8"></script>
		<!--<script src="../js/common/flexible.debug.js" type="text/javascript" charset="utf-8"></script>-->
	</head>

	<body>
		<div style="padding:200px 0 0 200px;">
			<button onclick="shareShow()">分 享</button>
			<button onclick="shareSystem()">发送系统分享</button>
		</div>
		<script src="../js/h5.js" type="text/javascript" charset="utf-8"></script>
		<script>
			var shares=null;
			// H5 plus事件处理
			function plusReady(){
				updateSerivces();
			}
			if(window.plus){
				plusReady();
			}else{
				document.addEventListener('plusready', plusReady, false);
			}
			
			// 通过系统组件分享 
			function shareSystem(){
				plus.share.sendWithSystem({content:'小宋的分享',href:'http://www.baidu.com'}, function(){
					console.log('分享成功');
				}, function(e){
					console.log('分享失败：'+JSON.stringify(e));
				});
			}
			/**
			 * 更新分享服务
			 */
			function updateSerivces(){
				plus.share.getServices(function(s){
					shares={};
					for(var i in s){
						var t=s[i];
						shares[t.id]=t;
					}
				}, function(e){
					alert('获取分享服务列表失败：'+e.message);
				});
			}
			
			// 打开分享
			function shareShow(){
				var shareBts=[];
				// 更新分享列表
				var ss=shares['weixin'];
				if(navigator.userAgent.indexOf('qihoo')<0){  //在360流应用中微信不支持分享图片
					ss&&ss.nativeClient&&(shareBts.push({title:'微信朋友圈',s:ss,x:'WXSceneTimeline'}),
					shareBts.push({title:'微信好友',s:ss,x:'WXSceneSession'}));
				}
				ss=shares['sinaweibo'];
				ss&&shareBts.push({title:'新浪微博',s:ss});
				ss=shares['qq'];
				ss&&ss.nativeClient&&shareBts.push({title:'QQ',s:ss});
				// 弹出分享列表
				shareBts.length>0?plus.nativeUI.actionSheet({title:'分享',cancel:'取消',buttons:shareBts}, function(e){
					(e.index>0)&&shareAction(shareBts[e.index-1],false);
				}):plus.nativeUI.alert('当前环境无法支持分享操作!');
			}
			
			/**
			 * 分享操作
			 * @param {plus.share.ShareService} 
			 */
			function shareAction(s) {
				if ( !s ) {
					return;
				}
				console.log(JSON.stringify(s))
				if ( s.s.authenticated ) {
					shareMessage( s ); 
				} else {
					s.s.authorize( shareMessage, function(e){
						alert( "未进行认证" );
					});
				}
			}
			/**
			 * 发送分享消息
			 * @param {plus.share.ShareService} s
			 */
			function shareMessage(s){
				s.s.send( {content:"Hello"}, function(){
					alert( "分享成功！" );
				}, function(e){
					alert( "分享失败："+e.message );
				} );
			}
		</script>
	</body>
</html>